<?

/**
 * PhpMailer Builder class
 * @package simplemailer
 * @author Alberto Pardo Saleme <apardo@gmail.com>
 * @update 22/08/2007 01:48:25 p.m.
 * Copyright (C) 2005 - AdVerit S.A. <www.adverit.com>
 */
require_once(dirname(__FILE__) ."/SimpleMailerEngine.php");

class SimpleMailerPhpMailer extends SimpleMailerEngine
{
    function send()
    {
        // Building the phpMailer
        require_once(dirname(__FILE__) ."/../lib/phpMailer/class.phpmailer.php");
        $mail = new PHPMailer();
        $mail->IsHTML(true);
        $mail->IsSMTP();
        $mail->SMTPDebug = $this->debug;
        $mail->SMTPAuth  = true;
        $mail->Priority  = 5;
        $mail->Host      = $GLOBALS["CONF"]['mail']['host'];
        $mail->Username  = $GLOBALS["CONF"]['mail']['user'];
        $mail->Password  = $GLOBALS["CONF"]['mail']['pass'];
        $mail->SetLanguage('en', dirname(__FILE__) ."/../lib/phpMailer/language/");

        // SSL IS NOT SUPORTED IN phpMailer
        // $GLOBALS["CONF"]['mail']['ssl'] is not used.

        // Preparin From, subject and body
        list($from, $fromEmail) = $this->parseEmail($this->from);
        $mail->From      = $from;
        $mail->FromName  = $fromEmail;
        $mail->Sender    = $from;
        $mail->Subject   = $this->subject;

        if(count($this->arAttachments))
        {
            foreach($this->arAttachments as $attachment)
            {
                $mail->AddAttachment($attachment['path']);
            }
        }

        $mail->Body      = $this->body;

        // Preparing recipients
        $recipients = $this->parseEmailsList($this->to);
        foreach($recipients AS $recipient)
        {
            $mail->AddAddress($recipient[0], $recipient[1]);
        }

        if (!$mail->send())
        {
            $this->_error($mail->ErrorInfo);
            return 0;
        }
        return 1;
    }
}

?>
